package models

import "gorm.io/gorm"

type House struct {
	gorm.Model
	Title       string  `gorm:"type:varchar(30)"`
	Price       float64 `gorm:"type:decimal(10,2)"`
	Address     string  `gorm:"type:varchar(50)"`
	Area        int     `gorm:"type:int(10)"`
	HouseStatus int     `gorm:"type:int;default:1;comment:房屋状态: 1 在售 0 下架"`
	UserId      int     `gorm:"type:int"`
}

func (h *House) Create() error {
	return DB.Create(&h).Error
}
func (h *House) HouseList() (houseList []*House, err error) {
	err = DB.Model(&h).Where("title like ?", "%"+h.Title+"%").Order("Created_At desc").Find(&houseList).Error
	return
}
